import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn,  $Lazy } = window
// ===================================================================== Lazy
const Page 				= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
const $time 			= $Lazy.file(()=>import('@com/utils/time'))
const ControlModal 		= $Lazy.state(()=>import('./cpt/control-modal'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '条码号',			name: 'spec_code' },
			{ label: '客户名称',			name: 'hosp_id',					type: 'select', loading:true },
			/* 收入成本明细增加身份证查询 2021-08-18  --耿琰 */
			{ label: '身份证号',			name: 'card_no' },
			{ label: '实验科室',			name: 'project_parent_id', 			type: 'select', loading:true,idStr:'id' },
			{ label: '区域',			name: 'region_id', 					type: 'select', loading:true },
			{ label: '接收标本时间',		names: ['start_at','end_at'], 		name:'jz-time', 	type:'date-range', format:1 },
			{ label: '账单创建日期',		names: ['bill_start_at','bill_end_at'], name:'time-null', type:'date-range' },
			{ label: '业务员',			name: 'salesman_id', 				type: 'select', loading:true },
			{ label: '姓名',			name: 'patient_name' },
			{ label: '项目名称',			name: 'kind_id', type: 'select' },
			{ label: '状态',			name: 'status',						type: 'select', loading:true, idStr:'code' },
			{ label: '账单类型',			name: 'pay_type',					type: 'select', loading:true }
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		// 设置时间默认值
		$time.then(f=>{
			const arr = f.duration['1-today']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 客户名称
			$fn.setRow(forms, 'hosp_id', await f.getCache({ api:'hospital' } ) ) 
			// 实验科室
			$fn.setRow(forms, 'project_parent_id', await f.getCache({ api:'shi_yan_ke_shi' } ) ) 
			// 区域
			$fn.setRow(forms, 'region_id', await f.getCache({ api:'bs_area' } ) ) 
			// 业务员
			$fn.setRow(forms, 'salesman_id', await f.getCache({ api:'salesman' } ) )
			// 状态
			$fn.setRow(forms, 'status', await f.getDicCache({ code:45300 } ) )
			// 账单类型
			$fn.setRow(forms, 'pay_type', await f.bill_type )
			// 项目名称
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'labkindselect' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'bill-st/detailindex', {isIndex:true})
	
	// 表单
	cols = [
		{ title: '岗位',				dataIndex: 'project_name', 				width:150 },
		{ title: '采集类型',				dataIndex: 'collect_type_name', 		width:100 },
		{ title: '接收时间',				dataIndex: 'check_time', 				...$fn.table.time },
		{ title: '客户名称',				dataIndex: 'hosp_name', 				width:250 },
		{ title: '条码号',				dataIndex: 'old_spec_code', 			...$fn.table.spec_code },
		/* 收入成本明细报告添加字段显示第三方条码 2021-08-16  --耿琰 */
		{ title: '第三方条码', 			dataIndex: 'third_spec_code', 			width:120 },
		{ title: '自然项目',				dataIndex: 'parent_kind_name', 			width:250 },
		{ title: '项目名称',				dataIndex: 'kind_name', 				width:250 },
		{ title: '标准价格',				dataIndex: 'sprice', 					...$fn.table.num },
		{ title: '实际价格',				dataIndex: 'price', 					...$fn.table.num },
		// 新增初始结算价字段 20211018 耿琰
		{ title: '初始结算价',			dataIndex: 'initial_price', 			...$fn.table.num },
		{ title: '姓名',				dataIndex: 'patient_name', 				...$fn.table.name },
		/* 收入成本明细增加身份证查询 2021-08-18  --耿琰 */
		{ title: '身份证号',				dataIndex: 'card_no', 					...$fn.table.idcard },
		{ title: '性别',				dataIndex: 'sex_name', 					...$fn.table.sex },
		{ title: '年龄',				dataIndex: 'age', 						...$fn.table.age },
		{ title: '送检科室',				dataIndex: 'department_name', 			width:150 },
		{ title: '医生',				dataIndex: 'doctor', 					...$fn.table.name },
		{ title: '备注',				dataIndex: 'remark', 					width:150 },
		{ title: '账单属性',				dataIndex: 'attribute_name', 			width:100 },
		{ title: '实验科室',				dataIndex: 'project_parent_name', 		width:150 },
		{ title: '外送单位',				dataIndex: 'outsourcing_company', 		width:150 },
		{ title: '开票单位（NC）',		dataIndex: 'organization_name', 		width:150 },
		{ title: '开票单位编码（NC）',	dataIndex: 'organization_code', 		width:150 },
		{ title: '账单创建日期', 		dataIndex: 'bill_created_at', 			...$fn.table.time },
		{ title: '业务员',				dataIndex: 'salesman_user', 			...$fn.table.name },
		{ title: '业务员编码',			dataIndex: 'salesman_code', 			width:150 },
		{ title: '区域',				dataIndex: 'region_name', 				width:150 },
		{ title: '区域编码',				dataIndex: 'region_num', 				...$fn.table.num },
		TableControls.controls.call(this)
	]
	
	// 表格操作按钮
	table_controls = (text, rows) => {
		return [
			TableControls.click.call(this, '账单信息', ()=> this.modal.open(rows) )
		]
	}
	
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this, 'bill-st/detailindex', { isSock: true })			// 导出
		]
	}
	render(){
		return (
			<>
				<Page title='收入成本明细' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this, { timeStr:'1-today' }) }
					{/* 表格 */}
					{ Table.call(this,{ onSelectOk:( key , rows ) => this.tableRef.fetch(rows), isIndex:true, isInit: window.isInit }) }
				</Page>
				{/* 账单信息 */}
				<ControlModal onRef={ref=>this.modal=ref} />
			</>
		)
	}
}

export default Index